﻿using TeamTasker.Contracts;
using TeamTasker.Server.DataAccess;
using System.Collections.Generic;
using System;

namespace TeamTasker.Server.BusinessLogic
{
    public class TeamFacade : BaseFacade<Team, TeamDAO>
    {
        public override void Save(Team entity)
        {
            if (entity.ID == 0)
            {
                entity.CreationDate = DateTime.Now;
            }
            base.Save(entity);
        }

        public IList<Team> GetTeams(long userID)
        {
            IList<Team> result = new List<Team>();
            IList<long> ids = Dao.GetTeamIDs(userID);
            foreach (long id in ids)
            {
                Team team = Load(id);
                result.Add(team);
            }
            return result;
        }

        public void UpdateMembers(long teamID,
                                  IList<TeamMember> membersToAdd,
                                  IList<TeamMember> membersToUpdate,
                                  IList<TeamMember> membersToDelete)
        {
            Dao.UpdateMembers(teamID, membersToAdd, membersToUpdate, membersToDelete);
        }
    }
}
